#include <stdatomic.h>
#include <threads.h>

atomic_flag flag = ATOMIC_VAR_INIT(0);

int func(void *data){
    while(!flag){
        /* ... */
    }
    return 0;
}

int main(void){
    int result;
    thrd_t tid;

    if(thrd_success != thrd_create(&tid,func,NULL)){
        /* Handle error */
    }
    /* ... */
    /* Set flag when done */
    while(!atomic_flag_test_and_set(&flag));
    return 0;
}